import React from 'react';
import {connect} from 'dva';
import PropTypes from 'prop-types';
import {Button,Row,Col,Layout,Spin,Icon,Input,Card,message, Form} from 'antd';
import  createClass  from 'create-react-class'
import style from './Login.less';
import {Link} from 'dva/router'
// import reqwest from 'reqwest';
// import InStyle from '../../styles/Info.less'
import First from './Regist/First.jsx'
import Post from './Regist/Post.jsx'
// import EditableCell from '../../components/EditableCell.js'
import {reqwest_post} from '../../utils/Reqwest.js'
const {  Content, Footer } = Layout;
// const { RangePicker } = DatePicker;

class Regist extends React.Component{
// const Regist = createClass
// createClass function Regist(){
	constructor(props){
		super(props);
		this.state={
			data:[],
      list:[],
		}
	}
  // static contextTypes = {
  // 	router: PropTypes.object
  // }
  componentWillMount(){
    // this.fetch(1);
    // console.log(this)
    // this.props.dispatch({type: 'regist/listEdit',payload:1})
    // console.log(_current)
    
  }
	handleSubmit(e){
		e.preventDefault();
		let _this = this;
		// this.setState({loading:true})
		const {regist} = this.props
		this.props.form.validateFields((err, values) => {
 			// console.log(values)
 			if(!err){
 				if( regist.page === "first"){ 
 					_this.props.dispatch({ type: 'regist/nextStep', payload: values})
 				}
 			}
    });
	}
  handleTabClick(e){
    
    if(e * 1 === 2){
      this.props.dispatch({type: 'orders/fetch',payload:{current:1,tab:'&type=children'}})
    }else{
      this.props.dispatch({type: 'orders/fetch',payload:{current:1,tab:''}})
    }

    this.setState({tab:e});

  }
  componentWillUnmount() {
    // this.reqwest_server.abort();
  }
  componentWillReceiveProps(){
  	// console.log(this)
  }
	render(){

		const {getFieldDecorator, getFieldValue, setFields} = this.props.form;
		const {regist} = this.props

		// let _page = [ <First decorator={getFieldDecorator} ispatch={this.props} /> , <post decorator={getFieldDecorator} ispatch={this.props} />]
		let _paga = {
			first: <First decorator={getFieldDecorator}  ispatch={this.props} /> ,
			post: <Post decorator={getFieldDecorator}  />
		}
    return(
      <Layout style={{background:'#000',height:'100%'}}>
      	<Form onSubmit={this.handleSubmit.bind(this)}>
      		<Row className={`${style.form_item}`}>
	      		<h1>注册</h1>
	      		<span>注册你的管家快销售账户</span>
      			{_paga[regist.page]}
      			<Col className={`${style.form_col}`}>已有账号，<Link to={{pathname:'/login'}}> 登录 </Link> <span> >> </span></Col>
	      	</Row>

      	</Form>
      </Layout> 
    )
	}
}
const RegistForm = Form.create()(Regist);
Regist.contextTypes = {
  router: PropTypes.object
};
// <First decorator={getFieldDecorator} ispatch={this.props.dispatch} />

export default connect(({regist}) => ({regist}))(RegistForm);
